<template>
  <div class="getsample">
    <a-card :bordered="false" style="border-radius:8px;margin-top:10px">
      <div class="card_title">
        商品寄样
      </div>
      <div class="groupbox flex row_bet flex_wrap" style="margin-bottom: 19px">
        <a-radio-group v-model="status" style="margin-bottom: 5px;" @change="statusChange">
          <a-radio-button :value="3">
            全部
          </a-radio-button>
          <a-radio-button :value="1">
            已收到
          </a-radio-button>
          <a-radio-button :value="2">
            未收到
          </a-radio-button>
        </a-radio-group>
        <div>
          <a-input-search
            placeholder="商品ID / 店铺名 / 运单号"
            style="width: 200px;margin-right:10px;margin-bottom:5px;"
            v-model="search"
            allowClear
            @search="onSearch"
          />
          <a-button type="primary" icon="plus" @click="drawershow = true" class="br4">
            添加信息
          </a-button>
        </div>
      </div>
      <a-table
        :columns="columns"
        :rowKey="activity => activity.id"
        :dataSource="activity"
        :loading="loading"
        @change="handleTableChange"
        :pagination="pagination"
      >
        <div slot="shopurl" slot-scope="text,row">
          <div class="line-3" style="width: 288px;">{{ row.shopurl }}</div>
        </div>
        <div slot="active" slot-scope="row">
          <div>
            <a-button type="link" @click="doedit(row)">编辑</a-button>
          </div>
          <a-button type="link" @click="goaudit(row)">删除</a-button>
        </div>
      </a-table>
    </a-card>
    <a-drawer
      title="添加信息"
      :width="513"
      :visible="drawershow"
      :body-style="{ paddingBottom: '80px' }"
      @close="onClose"
    >
      <div class="drawer1">
        <div class="titles">寄件人</div>
        <a-input v-model="form.sender" placeholder="寄件人" class="chooseipt br4"/>
        <div class="titles">商品链接</div>
        <a-textarea v-model="form.shopurl" :rows="4" placeholder="填写产品链接，一行一个" class="chooseipt br4" allowClear>
        </a-textarea>
        <div class="titles">运单号</div>
        <a-input v-model.number="form.tracking" placeholder="运单号" class="chooseipt br4"/>
        <div class="titles">产品名字</div>
        <a-input v-model="form.shopname" placeholder="产品名字" class="chooseipt br4"/>
        <div class="titles">退货地址</div>
        <a-input v-model="form.returnadd" placeholder="可不填" class="chooseipt"/>
        <div class="titles">备注</div>
        <a-input v-model="form.mark" placeholder="填写打款方式" class="chooseipt"/>
        <div class="titles">是否寄回</div>
        <a-radio-group v-model="form.send" class="chooseipt">
          <a-radio value="寄回" style="margin-right: 63px;">
            寄回
          </a-radio>
          <a-radio value="不寄">
            不寄
          </a-radio>
        </a-radio-group>
        <div
          :style="{
            position: 'absolute',
            right: 0,
            bottom: 0,
            width: '100%',
            borderTop: '1px solid #e9e9e9',
            padding: '10px 16px',
            background: '#fff',
            textAlign: 'right',
            zIndex: 1
          }"
        >
          <a-button type="primary" style="float:left;" :loading="btnloading" class="br4" @click="dosubmit">
            提 交 数 据
          </a-button>
        </div>
      </div>
    </a-drawer>
  </div>
</template>

<script>
  import { doaddconnectioninfo, getconnectionlist, updateconnectioninfo } from '@/api/dockingApi'
  import moment from 'moment'

  export default {
    name: 'Getsample',
    data () {
      return {
        moment,
        drawershow: false,
        status: 3,
        search: '',
        form: {
          sender: '',
          shopurl: '',
          tracking: '',
          shopname: '',
          returnadd: '',
          mark: '',
          send: ''
        },
        titleList: [],
        columns: [
          {
            title: '寄件人',
            align: 'left',
            dataIndex: 'sender',
            scopedSlots: {
              customRender: 'sender'
            }
          },
          {
            title: '运单号',
            align: 'center',
            dataIndex: 'tracking',
            scopedSlots: {
              customRender: 'tracking'
            }
          },
          {
            title: '产品名称',
            align: 'center',
            dataIndex: 'shopname',
            scopedSlots: {
              customRender: 'shopname'
            }
          },
          {
            title: '产品链接',
            align: 'center',
            dataIndex: 'shopurl',
            scopedSlots: {
              customRender: 'shopurl'
            }
          },
          {
            title: '是否寄回',
            align: 'center',
            dataIndex: 'send',
            scopedSlots: {
              customRender: 'send'
            }
          },
          {
            title: '抖音号',
            align: 'center',
            dataIndex: 'douyin',
            scopedSlots: {
              customRender: 'douyin'
            }
          },
          {
            title: '是否收到',
            align: 'center',
            dataIndex: 'receive',
            scopedSlots: {
              customRender: 'receive'
            }
          },
          {
            title: '拍摄情况',
            align: 'center',
            dataIndex: 'take',
            scopedSlots: {
              customRender: 'take'
            }
          },
          {
            title: '退货地址',
            align: 'center',
            dataIndex: 'returnadd',
            scopedSlots: {
              customRender: 'returnadd'
            }
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'mark',
            scopedSlots: {
              customRender: 'mark'
            }
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: {
              customRender: 'active'
            }
          }
        ],
        activity: [
          {
            id: 64, // 自增id
            user: '从雪艳', // 用户
            sender: '师姐', // 寄件人
            tracking: '圆通速递YT4124676667982', // 运单号
            shopname: '加厚铝合金罗马杆窗帘杆子', // 店铺名称
            shopurl: 'https://item.taobao.com/item.htm?id=539443743153', // 商品地址
            send: '拍完去拿', // 是否寄回
            receive: '', // 是否收到
            take: '', // 拍摄情况
            douyin: '', // 抖音号
            returnadd: '', // 退货地址
            mark: '', // 备注
            braId: 1 // 站点id、
          }
        ],
        loading: false,
        pagination: {
          pageSize: 15,
          page: 1
        },
        value: '',
        btnloading: false
      }
    },

    computed: {},
    created () {
      this.getconnectionlist(1, 15, 3)
    },
    mounted () {
    },
    methods: {
      doedit (row) {
        // console.log(row)
        this.form = row
        this.drawershow = true
      },
      onClose () {
        this.form = {}
        this.drawershow = false
      },
      goaudit (row) {
        this.$store.dispatch('setRowsname', row)
        this.$router.push({
          path: '/activity/finance/myAudit'
        })
      },
      handleChange2 (info) {
        const status = info.file.status
        // fin_fileName
        if (status !== 'uploading') {
          // console.log(info.file, info.fileList)
          this.form.fin_fileName = '//' + info.file.response.data.url
        }
        if (status === 'done') {
          this.$message.success(`${info.file.name} 上传成功!`)
        } else if (status === 'error') {
          this.$message.error(`${info.file.name} 上传失败!`)
        }
      },
      dosubmit () {
        this.btnloading = true
        // console.log(this.form)
        if (!this.form.id) {
          if (
            this.form.sender !== '' &&
            this.form.shopurl !== '' &&
            this.form.tracking !== '' &&
            this.form.shopname !== '' &&
            this.form.returnadd !== '' &&
            this.form.mark !== '' &&
            this.form.send !== ''
          ) {
            doaddconnectioninfo(this.form).then(res => {
              // console.log(res)
              if (res.code === 200) {
                this.$message.success('提交成功!')
                this.getconnectionlist(1, 15, 3)
                this.drawershow = false
                this.form = {}
                this.btnloading = false
              } else {
                this.btnloading = false
                this.$message.error(res.msg)
              }
            }).catch(err => {
              console.log(err)
            })
          } else {
            this.$message.info('请检查所需条件!')
          }
        } else {
          updateconnectioninfo(this.form).then(res => {
            // console.log(res)
            if (res.code === 200) {
              this.$message.success('修改成功!')
              this.getconnectionlist(1, 15, 3)
              this.drawershow = false
              this.form = {}
              this.btnloading = false
            } else {
              this.btnloading = false
              this.$message.error(res.msg)
            }
          }).catch(err => {
            console.log(err)
          })
        }
      },
      getconnectionlist (page, pagesize, status, search) {
        this.loading = true
        getconnectionlist({
          page: page,
          pagesize: pagesize,
          status: status, // 3全部，1已收到，2未收到
          search: search
        })
          .then(res => {
            // console.log(res)
            this.activity = res.data.data
            //  this.count = res.data.count
            const pagination = {
              ...this.pagination
            }
            pagination.total = res.data.count
            this.pagination = pagination
            this.loading = false
          })
          .catch(err => {
            console.log(err)
          })
      },
      handleTableChange (pagination, filters) {
        // console.log(pagination)
        const pager = {
          ...this.pagination
        }
        pager.current = pagination.current
        this.pagination = pager
        this.fetch({
          results: pagination.pageSize,
          page: pagination.current,
          ...filters
        })
      },
      fetch (params = {}) {
        // console.log('params:', params)
        this.loading = true
        this.getconnectionlist(params.page, 15, this.status, this.search)
      },
      onSearch (value) {
        // console.log(value)
        this.getconnectionlist(1, 15, this.status, this.search)
      },
      statusChange (e) {
        // console.log('radio checked', e.target.value)
        this.getconnectionlist(1, 15, this.status, this.search)
      },
      titleChange (value) {
        // console.log(`selected ${value}`)
        this.form.fin_shopName = value
      }
    }
  }
</script>
<style lang="less">
  .drawer1 {
    .titles {
      color: rgba(16, 16, 16, 100);
      font-size: 13px;
      text-align: left;
      margin-bottom: 8px;
    }

    .chooseipt {
      width: 100%;
      margin-bottom: 25px;
    }

    /deep/ .ant-input {
      border-radius: 4px;
    }

    /deep/ .ant-select-selection {
      border-radius: 4px;
    }
  }
</style>
<style lang="less" scoped>
  .getsample {
    .card_title {
      color: rgba(16, 16, 16, 100);
      font-size: 14px;
      margin-bottom: 15px;
      font-weight: 600;
    }

    .groupbox {
      /deep/ .ant-input {
        border-radius: 4px;
      }
    }

    /deep/ .ant-table-tbody {
      font-size: 13px;
    }
  }
</style>
